package com.cadre.system.domain.officer;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.system.*;

import java.text.ParseException;
import java.util.*;

/* loaded from: ToQueryParam.class */
public class ToQueryParam {
    private static final String AGE = "6";
    private static final String NAME_OR_RESUME = "2";
    private static final String EDUCATION = "118";
    private static final String XUELI = "30";
    private static final String SHUXILINGYU = "77";
    private static final String GONGZUOJINGLI = "53";
    private static final String ZHIJI = "13";
    private static final String GANBULEIBIE = "22";
    private static final String ZHIWULEIBIE = "50";
    private static final String ZHUANYELEIBIE = "36";
    private static final String RESUME = "999";
    private static final String UNITID = "998";
    private static final String BENGINBIRTHDAY = "997";
    private static final String ENDBIRTHDAY = "996";
    private static final String KEY = "tagId";
    private Map<String, String> basemap;
    private SQLStringBuild sqlBuilder;
    private String[] sqlparam;
    private List<String> list;

    public ToQueryParam(SQLStringBuild sqlBuilder) {
        this.sqlBuilder = sqlBuilder;
    }

    public ToQueryParam() {
    }

    public String[] toSql_bak(String json) {
        JSONArray array = JSON.parseArray(json);
        this.list = new ArrayList();
        this.sqlparam = new String[3];
        Iterator it = array.iterator();
        while (it.hasNext()) {
            Map<String, Object> map = (Map) it.next();
            if (map.get(KEY).equals(AGE)) {
                this.list.add(new AgeStringBuild().builder(map));
            } else if (map.get(KEY).equals(EDUCATION) || map.get(KEY).equals(XUELI)) {
                this.list.add(new EducationStringBuild().builder(map));
            } else if (map.get(KEY).equals(NAME_OR_RESUME)) {
                this.list.add(new NameStringBuild().builder(map));
            } else {
                this.list.add(new AndDefaultStringBuild().builder(map));
            }
        }
        this.sqlparam[2] = listToStr(this.list);
        return this.sqlparam;
    }

    public Map<String, Object> toSql(String json) {
        Map<String, Object> param = new HashMap<>();
        Iterator it = JSON.parseArray(json).iterator();
        while (it.hasNext()) {
            SearchHelper.convertQueryParam((Map) it.next(), param);
        }
        return param;
    }

    public Map<String, String> toSqlbak(String json) {
        Map<String, String> param = new HashMap<>();
        JSONArray array = JSON.parseArray(json);
        this.list = new ArrayList();
        Iterator it = array.iterator();
        while (it.hasNext()) {
            Map<String, Object> map = (Map) it.next();
            if (map.get(KEY).equals(GANBULEIBIE)) {
                this.list.add(new OrDefaultStringBuild().builder(map));
            } else if (map.get(KEY).equals(AGE)) {
                this.list.add(new AgeStringBuild().builder(map));
            } else if (map.get(KEY).equals(ZHIJI)) {
                this.list.add(new ZhijiStringBuild().builder(map));
            } else if (map.get(KEY).equals(EDUCATION)) {
                initMap();
                param.put("a0449", "1");
                String a0460 = "";
                JSONArray list = (JSONArray) map.get("valueString");
                for (int i = 0; i < list.size(); i++) {
                    if (i == 0) {
                        a0460 = this.basemap.get(list.getString(i));
                    } else {
                        a0460 = a0460 + "," + this.basemap.get(list.getString(i));
                    }
                }
                param.put("a0460", a0460);
            } else if (map.get(KEY).equals(XUELI)) {
                param.put("a0449", NAME_OR_RESUME);
                String a04602 = "";
                JSONArray list2 = (JSONArray) map.get("valueString");
                if (list2.size() > 1) {
                    param.put("a0449", null);
                }
                if (list2.getString(0).equals("研究生教育")) {
                    a04602 = " = 1 ";
                }
                if (list2.getString(0).equals("本科教育")) {
                    a04602 = " = 2 ";
                }
                if (list2.getString(0).equals("专科教育")) {
                    a04602 = " = 3 ";
                }
                if (list2.getString(0).equals("其他")) {
                    a04602 = " not in(1,2) or SUBSTR(a0460, 1, 1) is null ";
                }
                param.put("a0460", a04602);
            } else if (map.get(KEY).equals(SHUXILINGYU)) {
                this.list.add(new EducationStringBuild().builder(map));
            } else if (map.get(KEY).equals(GONGZUOJINGLI)) {
                this.list.add(new WorkExperienceStringBuild().builder(map));
            } else if (map.get(KEY).equals(ZHIWULEIBIE)) {
                JSONArray valuestring = (JSONArray) map.get("valueString");
                if (valuestring.size() > 1) {
                    param.put("lingdaozhiwu", "错误参数");
                } else {
                    param.put("lingdaozhiwu", valuestring.get(0).toString());
                }
            } else if (map.get(KEY).equals(ZHUANYELEIBIE)) {
                this.list.add(new ZhuanyeStringBuild().builder(map));
            } else if (map.get(KEY).equals(NAME_OR_RESUME)) {
                param.put("personParam", new NameStringBuild().builder(map));
            } else if (map.get(KEY).equals(RESUME)) {
                param.put("resumeParam", new ResumeStringBuild().builder(map));
            } else if (map.get(KEY).equals(UNITID)) {
                param.put("unitParam", ((JSONArray) map.get("valueString")).get(0).toString());
            } else if (map.get(KEY).equals(BENGINBIRTHDAY)) {
                param.put("beginBirthday", ((JSONArray) map.get("valueString")).get(0).toString());
            } else if (map.get(KEY).equals(ENDBIRTHDAY)) {
                String endBirthdy = null;
                try {
                    endBirthdy = DateUtil.subMonth(((JSONArray) map.get("valueString")).get(0).toString());
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                param.put("endBirthday", endBirthdy);
            } else {
                this.list.add(new AndDefaultStringBuild().builder(map));
            }
        }
        param.put("tagParam", listToStr(this.list));
        return param;
    }

    private String listToStr(List<String> list) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            if (i > 0) {
                sb.append(" intersect ");
            }
            sb.append(list.get(i));
        }
        return sb.toString();
    }

    public SQLStringBuild getSqlBuilder() {
        return this.sqlBuilder;
    }

    public void setSqlBuilder(SQLStringBuild sqlBuilder) {
        this.sqlBuilder = sqlBuilder;
    }

    private void initMap() {
        this.basemap = new HashMap();
        this.basemap.put("研究生教育", "1");
        this.basemap.put("本科教育", NAME_OR_RESUME);
        this.basemap.put("专科教育", "3");
        this.basemap.put("其他", "4,5,6,7,8");
    }
}
